const express = require('express');
const router = express.Router();
const { authenticateToken } = require('../middleware/auth');
const ResponseHelper = require('../util/response');

// 公开API路由
router.get('/public', (req, res) => {
  ResponseHelper.success(res, { message: 'This is a public API endpoint' });
});

// 受保护的API路由
router.get('/protected', authenticateToken, (req, res) => {
  ResponseHelper.success(res, { 
    message: 'This is a protected API endpoint',
    user: req.user 
  });
});

// 示例数据路由
router.get('/data', (req, res) => {
  const sampleData = [
    { id: 1, name: 'Item 1', description: 'Description 1' },
    { id: 2, name: 'Item 2', description: 'Description 2' },
    { id: 3, name: 'Item 3', description: 'Description 3' }
  ];
  
  ResponseHelper.success(res, sampleData, 'Data retrieved successfully');
});

// 分页示例路由
router.get('/paginated', (req, res) => {
  const page = parseInt(req.query.page) || 1;
  const limit = parseInt(req.query.limit) || 10;
  const total = 100; // 模拟总数据量
  
  const startIndex = (page - 1) * limit;
  const endIndex = startIndex + limit;
  
  const sampleData = Array.from({ length: limit }, (_, i) => ({
    id: startIndex + i + 1,
    name: `Item ${startIndex + i + 1}`,
    description: `Description for item ${startIndex + i + 1}`
  }));
  
  ResponseHelper.paginated(res, sampleData, page, limit, total, 'Paginated data retrieved');
});

module.exports = router;
